package com.xx.pmis.web.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.xx.pmis.model.LuckyData;
import com.xx.pmis.model.util.LuckyRed;


public class LuckyRedUtil {

	// 01
	public static LuckyRed GetLuckyRedOfR01(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR01("01");
		return luckyRed;
	}

	// 02
	public static LuckyRed GetLuckyRedOfR02(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR02("02");
		return luckyRed;
	}

	// 03
	public static LuckyRed GetLuckyRedOfR03(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR03("03");
		return luckyRed;
	}

	// 04
	public static LuckyRed GetLuckyRedOfR04(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR04("04");
		return luckyRed;
	}

	// 05
	public static LuckyRed GetLuckyRedOfR05(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR05("05");
		return luckyRed;
	}

	// 06
	public static LuckyRed GetLuckyRedOfR06(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR06("06");
		return luckyRed;
	}

	// 07
	public static LuckyRed GetLuckyRedOfR07(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR07("07");
		return luckyRed;
	}

	// 08
	public static LuckyRed GetLuckyRedOfR08(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR08("08");
		return luckyRed;
	}

	// 09
	public static LuckyRed GetLuckyRedOfR09(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR09("09");
		return luckyRed;
	}

	// 10
	public static LuckyRed GetLuckyRedOfR10(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR10("10");
		return luckyRed;
	}

	// 11
	public static LuckyRed GetLuckyRedOfR11(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR11("11");
		return luckyRed;
	}

	// 12
	public static LuckyRed GetLuckyRedOfR12(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR12("12");
		return luckyRed;
	}

	// 13
	public static LuckyRed GetLuckyRedOfR13(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR13("13");
		return luckyRed;
	}

	// 14
	public static LuckyRed GetLuckyRedOfR14(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR14("14");
		return luckyRed;
	}

	// 15
	public static LuckyRed GetLuckyRedOfR15(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR15("15");
		return luckyRed;
	}

	// 16
	public static LuckyRed GetLuckyRedOfR16(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR16("16");
		return luckyRed;
	}

	// 17
	public static LuckyRed GetLuckyRedOfR17(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR17("17");
		return luckyRed;
	}

	// 18
	public static LuckyRed GetLuckyRedOfR18(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR18("18");
		return luckyRed;
	}

	// 19
	public static LuckyRed GetLuckyRedOfR19(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR19("19");
		return luckyRed;
	}

	// 20
	public static LuckyRed GetLuckyRedOfR20(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR20("20");
		return luckyRed;
	}

	// 21
	public static LuckyRed GetLuckyRedOfR21(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR21("21");
		return luckyRed;
	}

	// 22
	public static LuckyRed GetLuckyRedOfR22(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR22("22");
		return luckyRed;
	}

	// 23
	public static LuckyRed GetLuckyRedOfR23(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR23("23");
		return luckyRed;
	}

	// 24
	public static LuckyRed GetLuckyRedOfR24(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR24("24");
		return luckyRed;
	}

	// 25
	public static LuckyRed GetLuckyRedOfR25(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR25("25");
		return luckyRed;
	}

	// 26
	public static LuckyRed GetLuckyRedOfR26(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR26("26");
		return luckyRed;
	}

	// 27
	public static LuckyRed GetLuckyRedOfR27(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR27("27");
		return luckyRed;
	}

	// 28
	public static LuckyRed GetLuckyRedOfR28(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR28("28");
		return luckyRed;
	}

	// 29
	public static LuckyRed GetLuckyRedOfR29(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR29("29");
		return luckyRed;
	}

	// 30
	public static LuckyRed GetLuckyRedOfR30(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR30("30");
		return luckyRed;
	}

	// 31
	public static LuckyRed GetLuckyRedOfR31(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR31("31");
		return luckyRed;
	}

	// 32
	public static LuckyRed GetLuckyRedOfR32(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR32("32");
		return luckyRed;
	}

	// 33
	public static LuckyRed GetLuckyRedOfR33(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = GetLuckyRed(ld, lr);
		luckyRed.setR33("33");
		return luckyRed;
	}

	// 红球
	public static LuckyRed GetLuckyRed(LuckyData ld, LuckyRed lr)
			throws NumberFormatException {
		LuckyRed luckyRed = lr;
		luckyRed.setIssueNumber(ld.getIssueNumber());
		luckyRed.setLuckyRedCode(ld.getR1() + " " + ld.getR2() + " "
				+ ld.getR3() + " " + ld.getR4() + " " + ld.getR5() + " "
				+ ld.getR6());
		luckyRed.setLuckyBlueCode(ld.getB1());
		return luckyRed;
	}
	
	// 红球初始化
	public static LuckyRed setNullOfLuckyRed(LuckyRed luckyRed)
			throws NumberFormatException {
		luckyRed.setR01("");
		luckyRed.setR02("");
		luckyRed.setR03("");
		luckyRed.setR04("");
		luckyRed.setR05("");
		luckyRed.setR06("");
		luckyRed.setR07("");
		luckyRed.setR08("");
		luckyRed.setR09("");
		luckyRed.setR10("");
		luckyRed.setR11("");
		luckyRed.setR12("");
		luckyRed.setR13("");
		luckyRed.setR14("");
		luckyRed.setR15("");
		luckyRed.setR16("");
		luckyRed.setR17("");
		luckyRed.setR18("");
		luckyRed.setR19("");
		luckyRed.setR20("");
		luckyRed.setR21("");
		luckyRed.setR22("");
		luckyRed.setR23("");
		luckyRed.setR24("");
		luckyRed.setR25("");
		luckyRed.setR26("");
		luckyRed.setR27("");
		luckyRed.setR28("");
		luckyRed.setR29("");
		luckyRed.setR30("");
		luckyRed.setR31("");
		luckyRed.setR32("");
		luckyRed.setR33("");

		return luckyRed;
	}

	// 查询所有双色球,红球
	public static List<LuckyRed> luckyDataOfRed(List<?> all) {
		List<LuckyRed> list = new ArrayList<LuckyRed>();
		Iterator<?> it = all.iterator();
		while (it.hasNext()) {
			LuckyData ld = (LuckyData) it.next();
			LuckyRed lr = new LuckyRed();
			setNullOfLuckyRed(lr);
			String[] s = new String[6];
			s[0] = ld.getR1();
			s[1] = ld.getR2();
			s[2] = ld.getR3();
			s[3] = ld.getR4();
			s[4] = ld.getR5();
			s[5] = ld.getR6();
		    for(int i = 0;i<s.length;i++){
				switch (Integer.parseInt(s[i])) {
				case 1:
					lr = GetLuckyRedOfR01(ld, lr);
					break;
				case 2:
					lr = GetLuckyRedOfR02(ld, lr);
					break;
				case 3:
					lr = GetLuckyRedOfR03(ld, lr);
					break;
				case 4:
					lr = GetLuckyRedOfR04(ld, lr);
					break;
				case 5:
					lr = GetLuckyRedOfR05(ld, lr);
					break;
				case 6:
					lr = GetLuckyRedOfR06(ld, lr);
					break;
				case 7:
					lr = GetLuckyRedOfR07(ld, lr);
					break;
				case 8:
					lr = GetLuckyRedOfR08(ld, lr);
					break;
				case 9:
					lr = GetLuckyRedOfR09(ld, lr);
					break;
				case 10:
					lr = GetLuckyRedOfR10(ld, lr);
					break;
				case 11:
					lr = GetLuckyRedOfR11(ld, lr);
					break;
				case 12:
					lr = GetLuckyRedOfR12(ld, lr);
					break;
				case 13:
					lr = GetLuckyRedOfR13(ld, lr);
					break;
				case 14:
					lr = GetLuckyRedOfR14(ld, lr);
					break;
				case 15:
					lr = GetLuckyRedOfR15(ld, lr);
					break;
				case 16:
					lr = GetLuckyRedOfR16(ld, lr);
					break;
				case 17:
					lr = GetLuckyRedOfR17(ld, lr);
					break;
				case 18:
					lr = GetLuckyRedOfR18(ld, lr);
					break;
				case 19:
					lr = GetLuckyRedOfR19(ld, lr);
					break;
				case 20:
					lr = GetLuckyRedOfR20(ld, lr);
					break;
				case 21:
					lr = GetLuckyRedOfR21(ld, lr);
					break;
				case 22:
					lr = GetLuckyRedOfR22(ld, lr);
					break;
				case 23:
					lr = GetLuckyRedOfR23(ld, lr);
					break;
				case 24:
					lr = GetLuckyRedOfR24(ld, lr);
					break;
				case 25:
					lr = GetLuckyRedOfR25(ld, lr);
					break;
				case 26:
					lr = GetLuckyRedOfR26(ld, lr);
					break;
				case 27:
					lr = GetLuckyRedOfR27(ld, lr);
					break;
				case 28:
					lr = GetLuckyRedOfR28(ld, lr);
					break;
				case 29:
					lr = GetLuckyRedOfR29(ld, lr);
					break;
				case 30:
					lr = GetLuckyRedOfR30(ld, lr);
					break;
				case 31:
					lr = GetLuckyRedOfR31(ld, lr);
					break;
				case 32:
					lr = GetLuckyRedOfR32(ld, lr);
					break;
				case 33:
					lr = GetLuckyRedOfR33(ld, lr);
					break;
				default:
					break;
				}	    	
		    }
		    list.add(lr);
		}
		return list;
	}
	
	// 出现总次数
	public static int[] totalNumberOfLuckyRed(List<LuckyRed> list) {
		int[] n = new int[33];
		initTotaNumberOfLuckyRed(n);
		Iterator<?> it = list.iterator();
		while(it.hasNext()) {
			LuckyRed lr = (LuckyRed)it.next();
			String[] s = new String[33]; 
			s = stringOfLuckyRed(lr);
			for(int i=0;i<s.length;i++){
				if(!s[i].equals("")) {
					n[i] ++;
				}				
			}
		}
		return n;
	}
	
	// 初始化整型数组为0
	public static void initTotaNumberOfLuckyRed(int[] n) {
		for(int i = 0;i<n.length;i++) {
			n[i]=0;
		}
	}
	
	// 定义一个长度为33的字符串数据
	public static String[] stringOfLuckyRed(LuckyRed lr) {
		String[] s = new String[33];
		s[0] = lr.getR01();
		s[1] = lr.getR02();
		s[2] = lr.getR03();
		s[3] = lr.getR04();
		s[4] = lr.getR05();
		s[5] = lr.getR06();
		s[6] = lr.getR07();
		s[7] = lr.getR08();
		s[8] = lr.getR09();
		s[9] = lr.getR10();
		s[10] = lr.getR11();
		s[11] = lr.getR12();
		s[12] = lr.getR13();
		s[13] = lr.getR14();
		s[14] = lr.getR15();
		s[15] = lr.getR16();		
		s[16] = lr.getR17();		
		s[17] = lr.getR18();
		s[18] = lr.getR19();
		s[19] = lr.getR20();
		s[20] = lr.getR21();
		s[21] = lr.getR22();
		s[22] = lr.getR23();
		s[23] = lr.getR24();
		s[24] = lr.getR25();
		s[25] = lr.getR26();
		s[26] = lr.getR27();
		s[27] = lr.getR28();		
		s[28] = lr.getR29();		
		s[29] = lr.getR30();
		s[30] = lr.getR31();
		s[31] = lr.getR32();
		s[32] = lr.getR33();
		
		return s;
	}
}
